package com.fitbet.wechat.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.fitbet.entity.user.User;
import com.fitbet.entity.user.UserTransaction;
import com.fitbet.entity.user.UserWithdrawal;
import com.fitbet.entity.user.Wallet;
import com.fitbet.wechat.dao.UserTransactionDao;
import com.fitbet.wechat.dao.WalletDao;
import com.fitbet.wechat.service.UserTransactionService;
/**
 * @author xiaoHU
 *
 */
@Service("userTransactionService")
public class UserTransactionServiceImpl implements UserTransactionService {

    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    @Dao
    private UserTransactionDao userTransactionDao;
    
    @Dao
    private WalletDao walletDao;
    
    /* (non-Javadoc)
     * @see com.fitbet.wechat.service.UserTransactionService#list()
     */
    public List<UserTransaction> list() {
        return userTransactionDao.list();
    }

    /* (non-Javadoc)
     * @see com.fitbet.wechat.service.UserTransactionService#createTransaction(com.fitbet.entity.user.User, int, java.lang.String)
     */
    public void createTransaction(User user, int price, String content) {
        
        Wallet wallet = walletDao.loadWallet(user);
        genericDaoSupport.update(wallet.outcome(price));
        
        UserTransaction userTransaction = new UserTransaction(user, price, "提现", content, false);
        genericDaoSupport.save(userTransaction.init());
        
        UserWithdrawal userWithdrawal = new UserWithdrawal(user,price,content);
        genericDaoSupport.save(userWithdrawal.init());
        
    }

}
